// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

const API_BASE_URL = '/api';

// 获取协议列表
export async function fetchAgreementList(params) {
  try {
    const response = await request(`${API_BASE_URL}/mj_agreement/queryAgreementByType`, {
      method: 'POST',
      data: params,
    });
    return { data: response.data, success: true, total: response.data.total };
  } catch (error) {
    throw new Error('Failed to fetch agreement list');
  }
}

// 创建协议
export async function createAgreement(agreement) {
  try {
    await request(`${API_BASE_URL}/mj_agreement`, {
      method: 'POST',
      data: agreement,
    });
  } catch (error) {
    throw new Error('Failed to create agreement');
  }
}

// 更新协议
export async function updateAgreement(agreement) {
  try {
    await request(`${API_BASE_URL}/mj_agreement/edit`, {
      method: 'POST',
      data: agreement,
    });
  } catch (error) {
    throw new Error('Failed to update agreement');
  }
}

// 删除协议
export async function deleteAgreement(id) {
  try {
    await request(`${API_BASE_URL}/mj_agreement/${id}`, {
      method: 'GET',
    });
  } catch (error) {
    throw new Error('Failed to delete agreement');
  }
}


// 友情链接


// 添加标签接口 /api/newTag/add 
export async function addLink(options?: { [key: string]: any }) {
  return request<API.RuleList>('/api/friendshipLink/add', {
    method: 'POST',
    data: {
      ...(options || {}),
    },
  });
}

// 修改标签接口  /api/newTag/edit
export async function editLink(options?: { [key: string]: any }) {
  return request<API.RuleList>('/api/friendshipLink/edit', {
    method: 'POST',
    data: {
      ...(options || {}),
    },
  });
}

// 查询标签接口 /api/newTag/queryByPage
export async function queryLink(options?: { [key: string]: any }) {
  const result = await request('/api/friendshipLink/queryByPage', {
    method: 'POST',
    data: {
      ...(options || {}),
    },
  });

  return { data: result.data.records, success: true,total:result.data.total }
}

// 删除标签接口 /api/newTag/delete
export async function deleteLink(options?: { [key: string]: any }) {
  return request('/api/friendshipLink/delete', {
    method: 'get',
    params: {
      id:options
    },
  });
}
